home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung / Power-Programmierung (Tewi)(1994).iso / magazine / drdobbs / ddjcompr / ashford / test.c < prev   
C/C++ Source or Header  |  1991-04-29  |  738b  |  57 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. static void print_time (clock_t);
  5.  
  6. int main (void)
  7.  
  8. {
  9.     unsigned hh, mm, ss, tt;
  10.     long x;
  11.  
  12.     hh = 15;
  13.     mm = 59;
  14.     ss = 59;
  15.     tt = 9;
  16.  
  17.     x = hh;
  18.     x *= 60;
  19.     x += mm;
  20.     x *= 60;
  21.     x += ss;
  22.     x *= 10;
  23.     x += tt;
  24.  
  25.     x *= CLK_TCK;
  26.     x /= 10;
  27.  
  28.     print_time (x);
  29.  
  30.     return 0;
  31. }
  32.  
  33.  
  34.  
  35. static void print_time (clock_t t)
  36.  
  37. {
  38.     long t2;
  39.     unsigned t3;
  40.     unsigned hh, mm, ss;
  41.  
  42.     t2 = t * 10 / CLK_TCK;
  43.     hh = (unsigned) (t2 / 36000L);
  44.     t3 = (unsigned) (t2 % 36000L);
  45.     mm = t3 / 600;
  46.     t3 %= 600;
  47.     ss = t3 / 10;
  48.     t3 %= 10;
  49.  
  50.     fprintf (stdout, "Time: ");
  51.     if (hh)
  52.         fprintf (stdout, "%d:%02d:%02d.%01d\n", hh, mm, ss, t3);
  53.     else
  54.         fprintf (stdout, "%d:%02d.%01d\n", mm, ss, t3);
  55. }
  56.  
  57.